home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / demostuf / bigrot2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-07-25  |  11.6 KB  |  684 lines

  1. program rotatevild;
  2. {
  3.   VILD ROTATION #2
  4.   - af Bjarke Viksφe
  5.   mar 1994
  6.  
  7.   THIS PROGRAM WAS CODED BY BJARKE VIKS0E.
  8.   YOU ARE FREE TO DO WHATEVER YOU WANT WITH THIS PIECE OF CODE.
  9.   E-MAIL ME AT: dat92230@rix02.lyngbyes.dk IN 1994 FOR CHAT AND CODE.
  10. }
  11.  
  12. {$IFDEF DPMI}
  13.     Virker nu kun i real-mode pga. selvmodificerende kode!
  14.     Skift til REAL-MODE!!!!!
  15. {$ENDIF}
  16.  
  17. uses
  18.     DEMOINIT, ILBM256;
  19.  
  20. const
  21.     DEBUG = FALSE;
  22.     ScreenSeg = $A000;
  23.     maxY = 300;
  24.     c = 128;
  25.  
  26. var
  27.     i : integer;
  28.     tabel            : array[0..320] of integer;
  29.     xpostabel    : array[1..160] of integer;
  30.     relYtabel    : array[-300..300] of integer;
  31.     sinustabel  : array[0..639] of integer;
  32.     yoff            : integer;
  33.     v                : word;
  34.     vinkel1, vinkel2 : integer;
  35.     zpos            : word;
  36.     z                : longint;
  37.     inserted        : integer;
  38.  
  39.     screen : pScreen;
  40.  
  41. const
  42.     display1 : integer = $0000;
  43.     display2 : integer = $4000;
  44.  
  45.  
  46.  
  47. (*------------------------------------------------*)
  48.  
  49. procedure SwapDisplay; assembler;
  50. asm
  51.       mov    ax,display1
  52.    mov    dx,display2
  53.    mov    display1,dx
  54.     mov    display2,ax
  55.  
  56.     cli
  57.     mov    dx,$3D4
  58.     mov    al,$C
  59.     out    dx,al
  60.     inc    dx
  61.     mov    al,BYTE PTR display2+1
  62.     out    dx,al
  63.     mov    dx,$3D4
  64.     mov    al,$D
  65.     out    dx,al
  66.     inc    dx
  67.     mov    al,BYTE PTR display2
  68.     out    dx,al
  69.     sti
  70. end;
  71.  
  72.  
  73.  
  74. (*------------------------------------------------*)
  75.  
  76. procedure SetupSinus;
  77. var
  78.     i : integer;
  79.     v, vadd : real;
  80. begin
  81.     v:=0.0;
  82.     vadd:=(2.0*pi/512.0);
  83.     for i:=0 to 639 do
  84.     begin
  85.         sinustabel[i]:=round(sin(v)*32767);
  86.         v:=v+vadd;
  87.     end;
  88. end;
  89.  
  90. procedure SetupDemo;
  91. var
  92.     i : integer;
  93. begin
  94.     ClearWholeScreen;
  95.     SetupSinus;
  96.     v:=0;
  97.     zpos:=0;
  98.  
  99.     for i:=-maxy to maxy do relYtabel[i]:=i*320;
  100. end;
  101.  
  102.  
  103. (*------------------------------------------------*)
  104.  
  105.  
  106. procedure MakeXtabel; assembler;
  107. asm
  108.     push    es
  109.  
  110.    mov        ax,ds
  111.    mov        es,ax
  112.    lea        di,xpostabel
  113.     mov        cx,160
  114.     mov        dx,2
  115.     cld
  116. @makex1:
  117.     lea        si,tabel
  118.     mov        bx,dx
  119.    mov        bx,[si+bx]
  120.     lea        si,relYtabel+(maxy*2)
  121.    sal        bx,1
  122.     mov        ax,[si+bx]
  123.     stosw
  124.    add        dx,4
  125.    loop        @makex1
  126.  
  127.    mov        ax,ds
  128.    mov        es,ax
  129.     lea        si,tabel
  130.     lea        di,xpostabel
  131.     mov        cx,160
  132.     cld
  133. @makex:
  134.    mov        ax,[si]
  135.     add        [di],ax
  136.     add        si,4
  137.     add        di,2
  138.     loop    @makex
  139.  
  140.     pop        es
  141. end;
  142.  
  143.  
  144. procedure CalcVinkel;
  145. begin
  146.     vinkel1:=sinustabel[v AND 511];
  147.     vinkel2:=sinustabel[(v AND 511)+128];
  148.     inc(v,1);
  149.  
  150.     z:=(sinustabel[(zpos AND 511)] DIV 15)+2700;
  151.     inc(zpos,5);
  152. end;
  153.  
  154.  
  155. procedure RotateCoord(x,y : integer; VAR rx,ry : integer);
  156. var
  157.     cx,cy : longint;
  158. begin
  159.     cx := (longint(x)*vinkel2 - longint(y)*vinkel1) DIV 128;
  160.     cy := (longint(x)*vinkel1 + longint(y)*vinkel2) DIV 128;
  161.     rx := cx DIV z;
  162.     ry := cy DIV z;
  163. end;
  164.  
  165. (*------------------------------------------------*)
  166.  
  167. procedure CalcSlope(x1,y1,x2,y2, n : integer);
  168. var
  169.     x,y,delx,dely : longint;
  170. begin
  171.     delx := (x2-x1) * ($10000 DIV (n-1));
  172.     dely := (y2-y1) * ($10000 DIV (n-1));
  173.  
  174.     asm
  175.       xor        dx,dx
  176.         mov        ax,x1
  177.         mov        WORD PTR x,dx
  178.         mov        WORD PTR x+2,ax
  179.       mov        ax,y1
  180.         mov        WORD PTR y,dx
  181.         mov        WORD PTR y+2,ax
  182.  
  183.         lea        si,tabel
  184.         mov        di,n
  185.         mov        ax,WORD PTR x+2
  186.         mov        dx,WORD PTR x
  187.         mov        bx,WORD PTR y+2
  188.         mov        cx,WORD PTR y
  189. @loop1:
  190.         add        dx,WORD PTR delx
  191.         adc        ax,WORD PTR delx+2
  192.         mov        [si],ax
  193.         add        si,2
  194.         add        cx,WORD PTR dely
  195.         adc        bx,WORD PTR dely+2
  196.         mov        [si],bx
  197.         add        si,2
  198.         dec        di
  199.         jnz        @loop1
  200.  
  201.         mov        ax,ds
  202.         mov        es,ax
  203.         lea        si,tabel
  204.       mov        di,si
  205.         mov        cx,n
  206.       shl        cx,1
  207.       cld
  208. @loop2:
  209.       lodsw
  210.         sar        ax,7
  211.       stosw
  212.         loop        @loop2
  213.     end;
  214. end;
  215.  
  216.  
  217. procedure BigScreenRotator(x,y : integer);
  218. var
  219.     XYoffset : integer;
  220.     screenoffset : integer;
  221. begin
  222.     screenoffset := display1+yoff;
  223.  
  224.     asm
  225.         mov    ax,y
  226.         mov    dx,320
  227.         imul    dx
  228.         add    ax,x
  229.         mov    XYoffset,ax
  230.  
  231.  
  232.         cmp    inserted,0
  233.         jne    @noinsert
  234.         mov    inserted,1
  235.  
  236.         mov    ax,cs
  237.         mov    es,ax
  238.         lea    si,xpostabel
  239.         lea    di,@megaloop1+2
  240.         cld
  241.         mov    cx,40
  242. @insert1:
  243.         mov    ax,[si]
  244.         mov    [es:di],ax
  245.         add    si,4
  246.         add    di,4
  247.       mov    ax,[si]
  248.         mov    [es:di],ax
  249.       add    si,4
  250.         add    di,8
  251.         loop    @insert1
  252.  
  253.         lea    si,xpostabel+2
  254.         lea    di,@megaloop2+2
  255.         mov    cx,40
  256. @insert2:
  257.       mov    ax,[si]
  258.         mov    [es:di],ax
  259.       add    si,4
  260.         add    di,4
  261.         mov    ax,[si]
  262.         mov    [es:di],ax
  263.         add    si,4
  264.         add    di,8
  265.         loop    @insert2
  266. @noinsert:
  267.  
  268.        mov    dx,$3C4
  269.         mov    al,$02
  270.         out    dx,al
  271.         inc    dx
  272.         mov    al,0011b
  273.         out    dx,al
  274.  
  275.         push    ds
  276.         push    es
  277.  
  278.         mov        si,XYoffset
  279.         add        si,WORD PTR screen
  280.         add        si,(100*320)+160
  281.         mov        di,screenoffset
  282.         mov        ax,WORD PTR screen+2
  283.         mov        ds,ax
  284.         mov        ax,ScreenSeg
  285.         mov        es,ax
  286.         mov        bx,80
  287.         cld
  288. @megaloop1:
  289.         mov        al,[si+3000]
  290.         mov        ah,[si+3000]
  291.         mov        [es:di+bx],ax
  292.         stosw
  293.         mov        al,[si+3000]
  294.         mov        ah,[si+3000]
  295.       mov        [es:di+bx],ax
  296.         stosw
  297.         mov        al,[si+3000]
  298.         mov        ah,[si+3000]
  299.         mov        [es:di+bx],ax
  300.         stosw
  301.         mov        al,[si+3000]
  302.         mov        ah,[si+3000]
  303.         mov        [es:di+bx],ax
  304.         stosw
  305.         mov        al,[si+3000]
  306.         mov        ah,[si+3000]
  307.       mov        [es:di+bx],ax
  308.         stosw
  309.         mov        al,[si+3000]
  310.         mov        ah,[si+3000]
  311.       mov        [es:di+bx],ax
  312.         stosw
  313.         mov        al,[si+3000]
  314.         mov        ah,[si+3000]
  315.       mov        [es:di+bx],ax
  316.         stosw
  317.         mov        al,[si+3000]
  318.         mov        ah,[si+3000]
  319.         mov        [es:di+bx],ax
  320.         stosw
  321.         mov        al,[si+3000]
  322.         mov        ah,[si+3000]
  323.         mov        [es:di+bx],ax
  324.         stosw
  325.         mov        al,[si+3000]
  326.         mov        ah,[si+3000]
  327.       mov        [es:di+bx],ax
  328.         stosw
  329.         mov        al,[si+3000]
  330.         mov        ah,[si+3000]
  331.       mov        [es:di+bx],ax
  332.         stosw
  333.         mov        al,[si+3000]
  334.         mov        ah,[si+3000]
  335.       mov        [es:di+bx],ax
  336.         stosw
  337.         mov        al,[si+3000]
  338.         mov        ah,[si+3000]
  339.         mov        [es:di+bx],ax
  340.         stosw
  341.         mov        al,[si+3000]
  342.         mov        ah,[si+3000]
  343.         mov        [es:di+bx],ax
  344.         stosw
  345.         mov        al,[si+3000]
  346.         mov        ah,[si+3000]
  347.       mov        [es:di+bx],ax
  348.         stosw
  349.         mov        al,[si+3000]
  350.         mov        ah,[si+3000]
  351.       mov        [es:di+bx],ax
  352.         stosw
  353.         mov        al,[si+3000]
  354.         mov        ah,[si+3000]
  355.       mov        [es:di+bx],ax
  356.         stosw
  357.         mov        al,[si+3000]
  358.         mov        ah,[si+3000]
  359.         mov        [es:di+bx],ax
  360.         stosw
  361.         mov        al,[si+3000]
  362.         mov        ah,[si+3000]
  363.         mov        [es:di+bx],ax
  364.         stosw
  365.         mov        al,[si+3000]
  366.         mov        ah,[si+3000]
  367.       mov        [es:di+bx],ax
  368.         stosw
  369.         mov        al,[si+3000]
  370.         mov        ah,[si+3000]
  371.       mov        [es:di+bx],ax
  372.         stosw
  373.         mov        al,[si+3000]
  374.         mov        ah,[si+3000]
  375.       mov        [es:di+bx],ax
  376.         stosw
  377.         mov        al,[si+3000]
  378.         mov        ah,[si+3000]
  379.         mov        [es:di+bx],ax
  380.         stosw
  381.         mov        al,[si+3000]
  382.         mov        ah,[si+3000]
  383.         mov        [es:di+bx],ax
  384.         stosw
  385.         mov        al,[si+3000]
  386.         mov        ah,[si+3000]
  387.       mov        [es:di+bx],ax
  388.         stosw
  389.         mov        al,[si+3000]
  390.         mov        ah,[si+3000]
  391.       mov        [es:di+bx],ax
  392.         stosw
  393.         mov        al,[si+3000]
  394.         mov        ah,[si+3000]
  395.       mov        [es:di+bx],ax
  396.         stosw
  397.         mov        al,[si+3000]
  398.         mov        ah,[si+3000]
  399.         mov        [es:di+bx],ax
  400.         stosw
  401.         mov        al,[si+3000]
  402.         mov        ah,[si+3000]
  403.         mov        [es:di+bx],ax
  404.         stosw
  405.         mov        al,[si+3000]
  406.         mov        ah,[si+3000]
  407.       mov        [es:di+bx],ax
  408.         stosw
  409.         mov        al,[si+3000]
  410.         mov        ah,[si+3000]
  411.       mov        [es:di+bx],ax
  412.         stosw
  413.         mov        al,[si+3000]
  414.         mov        ah,[si+3000]
  415.       mov        [es:di+bx],ax
  416.         stosw
  417.         mov        al,[si+3000]
  418.         mov        ah,[si+3000]
  419.         mov        [es:di+bx],ax
  420.         stosw
  421.         mov        al,[si+3000]
  422.         mov        ah,[si+3000]
  423.         mov        [es:di+bx],ax
  424.         stosw
  425.         mov        al,[si+3000]
  426.         mov        ah,[si+3000]
  427.       mov        [es:di+bx],ax
  428.         stosw
  429.         mov        al,[si+3000]
  430.         mov        ah,[si+3000]
  431.       mov        [es:di+bx],ax
  432.         stosw
  433.         mov        al,[si+3000]
  434.         mov        ah,[si+3000]
  435.       mov        [es:di+bx],ax
  436.         stosw
  437.         mov        al,[si+3000]
  438.         mov        ah,[si+3000]
  439.         mov        [es:di+bx],ax
  440.         stosw
  441.         mov        al,[si+3000]
  442.         mov        ah,[si+3000]
  443.         mov        [es:di+bx],ax
  444.         stosw
  445.         mov        al,[si+3000]
  446.         mov        ah,[si+3000]
  447.       mov        [es:di+bx],ax
  448.         stosw
  449.  
  450.        mov    dx,$3C4
  451.         mov    al,$02
  452.         out    dx,al
  453.         inc    dx
  454.         mov    al,1100b
  455.         out    dx,al
  456.  
  457.         mov        di,screenoffset
  458. @megaloop2:
  459.         mov        al,[si+3000]
  460.         mov        ah,[si+3000]
  461.       mov        [es:di+bx],ax
  462.         stosw
  463.         mov        al,[si+3000]
  464.         mov        ah,[si+3000]
  465.       mov        [es:di+bx],ax
  466.         stosw
  467.         mov        al,[si+3000]
  468.         mov        ah,[si+3000]
  469.       mov        [es:di+bx],ax
  470.         stosw
  471.         mov        al,[si+3000]
  472.         mov        ah,[si+3000]
  473.       mov        [es:di+bx],ax
  474.         stosw
  475.         mov        al,[si+3000]
  476.         mov        ah,[si+3000]
  477.       mov        [es:di+bx],ax
  478.         stosw
  479.         mov        al,[si+3000]
  480.         mov        ah,[si+3000]
  481.       mov        [es:di+bx],ax
  482.         stosw
  483.         mov        al,[si+3000]
  484.         mov        ah,[si+3000]
  485.       mov        [es:di+bx],ax
  486.         stosw
  487.         mov        al,[si+3000]
  488.         mov        ah,[si+3000]
  489.       mov        [es:di+bx],ax
  490.         stosw
  491.         mov        al,[si+3000]
  492.         mov        ah,[si+3000]
  493.       mov        [es:di+bx],ax
  494.         stosw
  495.         mov        al,[si+3000]
  496.         mov        ah,[si+3000]
  497.       mov        [es:di+bx],ax
  498.         stosw
  499.         mov        al,[si+3000]
  500.         mov        ah,[si+3000]
  501.       mov        [es:di+bx],ax
  502.         stosw
  503.         mov        al,[si+3000]
  504.         mov        ah,[si+3000]
  505.       mov        [es:di+bx],ax
  506.         stosw
  507.         mov        al,[si+3000]
  508.         mov        ah,[si+3000]
  509.       mov        [es:di+bx],ax
  510.         stosw
  511.         mov        al,[si+3000]
  512.         mov        ah,[si+3000]
  513.       mov        [es:di+bx],ax
  514.         stosw
  515.         mov        al,[si+3000]
  516.         mov        ah,[si+3000]
  517.       mov        [es:di+bx],ax
  518.         stosw
  519.         mov        al,[si+3000]
  520.         mov        ah,[si+3000]
  521.       mov        [es:di+bx],ax
  522.         stosw
  523.         mov        al,[si+3000]
  524.         mov        ah,[si+3000]
  525.       mov        [es:di+bx],ax
  526.         stosw
  527.         mov        al,[si+3000]
  528.         mov        ah,[si+3000]
  529.       mov        [es:di+bx],ax
  530.         stosw
  531.         mov        al,[si+3000]
  532.         mov        ah,[si+3000]
  533.       mov        [es:di+bx],ax
  534.         stosw
  535.         mov        al,[si+3000]
  536.         mov        ah,[si+3000]
  537.       mov        [es:di+bx],ax
  538.         stosw
  539.         mov        al,[si+3000]
  540.         mov        ah,[si+3000]
  541.       mov        [es:di+bx],ax
  542.         stosw
  543.         mov        al,[si+3000]
  544.         mov        ah,[si+3000]
  545.       mov        [es:di+bx],ax
  546.         stosw
  547.         mov        al,[si+3000]
  548.         mov        ah,[si+3000]
  549.       mov        [es:di+bx],ax
  550.         stosw
  551.         mov        al,[si+3000]
  552.         mov        ah,[si+3000]
  553.       mov        [es:di+bx],ax
  554.         stosw
  555.         mov        al,[si+3000]
  556.         mov        ah,[si+3000]
  557.       mov        [es:di+bx],ax
  558.         stosw
  559.         mov        al,[si+3000]
  560.         mov        ah,[si+3000]
  561.       mov        [es:di+bx],ax
  562.         stosw
  563.         mov        al,[si+3000]
  564.         mov        ah,[si+3000]
  565.       mov        [es:di+bx],ax
  566.         stosw
  567.         mov        al,[si+3000]
  568.         mov        ah,[si+3000]
  569.       mov        [es:di+bx],ax
  570.         stosw
  571.         mov        al,[si+3000]
  572.         mov        ah,[si+3000]
  573.       mov        [es:di+bx],ax
  574.         stosw
  575.         mov        al,[si+3000]
  576.         mov        ah,[si+3000]
  577.       mov        [es:di+bx],ax
  578.         stosw
  579.         mov        al,[si+3000]
  580.         mov        ah,[si+3000]
  581.       mov        [es:di+bx],ax
  582.         stosw
  583.         mov        al,[si+3000]
  584.         mov        ah,[si+3000]
  585.       mov        [es:di+bx],ax
  586.         stosw
  587.         mov        al,[si+3000]
  588.         mov        ah,[si+3000]
  589.       mov        [es:di+bx],ax
  590.         stosw
  591.         mov        al,[si+3000]
  592.         mov        ah,[si+3000]
  593.       mov        [es:di+bx],ax
  594.         stosw
  595.         mov        al,[si+3000]
  596.         mov        ah,[si+3000]
  597.       mov        [es:di+bx],ax
  598.         stosw
  599.         mov        al,[si+3000]
  600.         mov        ah,[si+3000]
  601.       mov        [es:di+bx],ax
  602.         stosw
  603.         mov        al,[si+3000]
  604.         mov        ah,[si+3000]
  605.       mov        [es:di+bx],ax
  606.         stosw
  607.         mov        al,[si+3000]
  608.         mov        ah,[si+3000]
  609.       mov        [es:di+bx],ax
  610.         stosw
  611.         mov        al,[si+3000]
  612.         mov        ah,[si+3000]
  613.       mov        [es:di+bx],ax
  614.         stosw
  615.         mov        al,[si+3000]
  616.         mov        ah,[si+3000]
  617.       mov        [es:di+bx],ax
  618.         stosw
  619.  
  620.         pop        es
  621.         pop        ds
  622.     end;
  623. end;
  624.  
  625.  
  626. procedure RotateScreen;
  627. var
  628.     x, y    : integer;
  629.     i        : integer;
  630. begin
  631.     yoff := 0;
  632.    inserted := 0;
  633.    i := 0;
  634.     while (i<200) do
  635.     begin
  636.         x:=tabel[i]; y:=tabel[i+1];
  637.         BigScreenRotator(x,y);
  638.         inc(i,2);
  639.         inc(yoff,width*2);
  640.     end;
  641. end;
  642.  
  643.  
  644. (*------------------------------------------------*)
  645.  
  646. procedure RunOnce;
  647. var
  648.     i : integer;
  649.     x1,y1, x2,y2 : integer;
  650. begin
  651.     SwapDisplay;
  652.     while retraces=0 do ;
  653.     retraces:=0;
  654.     if DEBUG then setrgb(0,63,0,0);
  655.     CalcVinkel;
  656.  
  657.     RotateCoord(-200*c,0,x1,y1);
  658.     RotateCoord(200*c,0,x2,y2);
  659.     CalcSlope(x1,y1,x2,y2,160);
  660.     MakeXtabel;
  661.  
  662.     RotateCoord(0,-180*c,x1,y1);
  663.     RotateCoord(0,180*c,x2,y2);
  664.     inc(x1,160); inc(x2,160);
  665.     inc(y1,100); inc(y2,100);
  666.     CalcSlope(x1,y1,x2,y2,100);
  667.     RotateScreen;
  668.     if DEBUG then setrgb(0,0,0,0);
  669. end;
  670.  
  671.  
  672. begin
  673.     new(screen);
  674.     LoadPix(screen, 'parasit1.lbm');
  675.     OpenScreen;
  676.     SetCMAP;
  677.     SetupDemo;
  678.     SetAllInterrupts;
  679.     while (not KeyPressed) do RunOnce;
  680.     RestoreAllInterrupts;
  681.     CloseScreen;
  682.     dispose(screen)
  683. end.
  684.